﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Bll.UserBase;
using Besture.Common;
using Besture.Common.Helper;
using Besture.UI.Common;

namespace Besture.UI.Portal.UserCenter
{
    public partial class Collection : UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InLoadBind();
                if (!string.IsNullOrEmpty(StringHelper.Query("ID")))
                {
                    try
                    {
                        var model = new CollectDac().GetModel(Convert.ToInt32(StringHelper.Query("ID")));
                        if (model == null)
                        {
                            FunHelper.Alert("取消失败", "/Portal/UserCenter/Collection.aspx");
                            return;

                        }else{

                            model.IsDeleted = 1;
                            if (new CollectDac().Update(model) > 0)
                            {
                                FunHelper.Alert("取消成功", "/Portal/UserCenter/Collection.aspx");
                            }
                        }

                    }
                    catch (Exception)
                    {
                        FunHelper.Alert("取消失败!", "/Portal/UserCenter/Collection.aspx");
                    }
                }
            }
        }

        private void InLoadBind()
        {
            var vDt = new CollectDac().GetDataTableByUserId(LoginUserInfo.ID);
            if (vDt != null)
            {
                AspNetPager1.RecordCount = vDt.Rows.Count;
                PagedDataSource pds1 = new PagedDataSource
                {
                    AllowPaging = true,
                    DataSource = vDt.DefaultView,
                    PageSize = AspNetPager1.PageSize,
                    CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1
                };
                rpCollect.DataSource = pds1;
                rpCollect.DataBind();
            }
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            InLoadBind();
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;

        }
         
    }
}